package cn.caixiong.org.service.impl;



import cn.caixiong.basic.util.PageList;
import cn.caixiong.org.domain.Department;
import cn.caixiong.org.domain.Syst;
import cn.caixiong.org.mapper.SystMapper;
import cn.caixiong.org.query.SystQuery;
import cn.caixiong.org.service.ISystService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class SystServiceImpl implements ISystService {
    @Autowired
    private SystMapper systMapper;

    @Override
    public List<Syst> findAll() {
        return systMapper.selectAll();
    }

    @Override
    public void saveOrUpdate(Syst syst) {
        if (syst.getId() == null){
            systMapper.insertSelective(syst);
        }else{
            systMapper.updateByPrimaryKeySelective(syst);

        }

    }

    @Override
    public void delete(Long id) {
        systMapper.deleteByPrimaryKey(id);

    }

    @Override
    public PageList<Syst> findPage(SystQuery query) {
        //1.使用分页工具类
        PageHelper.startPage(query.getPage(),query.getSize());
        //2.执行查询
        List<Syst> departments = systMapper.selectAll();
        //3.封装结果
        PageInfo<Syst> pageInfo = new PageInfo<>(departments);
        //4.封装我的自定义对象
        PageList<Syst> pageList = new PageList<>(pageInfo.getTotal(), pageInfo.getList());
        return pageList;
    }

    @Override
    public void batchDelete(Long[] ids) {
        if (ids.length==0){
            return;
        }
        for (Long id : ids) {
            systMapper.deleteByPrimaryKey(id);
        }

    }
}
